package com.novacloud.controller;

import com.novacloud.core.BaseController;
import com.novacloud.core.Result;
import com.novacloud.dao.MongoInfoRepository;
import com.novacloud.domain.MongoInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author <a href="mailto:huzhanjun@novacloud.com">huzj</a>
 * @version 1.0
 * @date 2017/10/12 9:51
 */
@RestController
@RequestMapping("/api/mongo")
public class MongoController extends BaseController{
    @Autowired
    private MongoInfoRepository mongoInfoRepository;

    @GetMapping("add")
    public Result add() {
        MongoInfo mongoInfo = new MongoInfo();
        mongoInfo.setName("demo");
        mongoInfo.setAge(11);
        mongoInfoRepository.save(mongoInfo);
        return resultSuccess(mongoInfo);
    }

    @GetMapping("find")
    public Result find() {
        return resultSuccess(mongoInfoRepository.findAll());
    }
}
